let payAcctAlterDao = module.exports;
let util = require('util');
let mysqlPool = require('./MySQLPool');

/*
id
uid
type
oldAcct
newAcct
create_time
 */
payAcctAlterDao.save = async function(acct) {

    let sql = 'insert into pay_acct_alter_log (uid, type, old_acct_no, new_acct_no, old_realname, create_time)' +
        '                    values (?,   ?,    ?,       ?,  ?, now())';
    let args = [acct.uid, acct.type, acct.oldAcct, acct.newAcct, acct.oldRealName];
    let res = await mysqlPool.query(sql, args);
    if (res){
        return res.insertId;
    }

    return 0;
};

payAcctAlterDao.update = async function (acct) {
    // if (psql == null) psql = P.promisifyAll(mysql);
    //
    // let sql = 'update pay_acct set acct_no = ?, realname = ? where uid = ? and type = ?';
    // let args = [acct.acct, acct.realName, acct.uid, acct.type];
    // let res = await psql.queryAsync(sql, args);
    // if (res){
    //     let affected = res.affectedRows
    //     return affected
    // }

    return 0;
};

payAcctAlterDao.get = async function(acct) {
    // if (psql == null) psql = P.promisifyAll(mysql);
    //
    // let sql = 'select * from pay_acct where uid = ? and type = ? limit 1';
    // let args = [acct.uid, acct.type];
    // let res = await psql.queryAsync(sql, args);
    // if (res){
    //     return res[0]
    // }

    return null;
};